package com.sky.moduels.mini.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.sky.moduels.mini.repository.dao.UserDao;
import com.sky.moduels.mini.repository.model.UserDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Description: 用户业务处理
 * @ClassName: UserService
 * @Author: hupengming
 * @CreateTime: 2022-08-19 11:09
 */
@Service
public class UserService {

    @Autowired
    private UserDao userDao;

    /**
     * openId获取用户
     *
     * @param openId
     * @return
     */
    public UserDO getUserByOpenId(String openId) {
        return userDao.selectOne(new LambdaQueryWrapper<UserDO>().eq(UserDO::getOpenId, openId));
    }

    /**
     * 创建用户
     *
     * @param userDO
     * @return
     */
    public void createdUser(UserDO userDO) {
        userDao.insert(userDO);
    }

    /**
     * 更新用户
     *
     * @param userDO
     * @return
     */
    public void updateUser(UserDO userDO) {
        userDao.update(userDO, new LambdaQueryWrapper<UserDO>().eq(UserDO::getOpenId, userDO.getOpenId()));
    }

}
